#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize) {
    if (!nums1Size || !nums1Size) {
        *returnSize = 0;
        return 0;
    }
    int min = nums1Size < nums2Size ? nums1Size : nums2Size;
    int* num = (int*)malloc(sizeof(int) * min);
    int count = 0;
    for (int i = 0; i < nums1Size; i++) {
        int flag = 0;
        for (int j = 0; j < nums2Size; j++) {
            if (nums1[i] == nums2[j]) {
                for (int k = 0; k < min; k++) {
                    if (num[k] == nums1[i])
                        flag = 1;
                        break;
                }
                if (flag != 1)
                    num[count++] = nums1[i];
            }
        }
    }
    *returnSize = count;
    return num;
}
int main() {
    int nums1[] = { 1, 2, 3, 5 };
    int nums2[] = { 2, 3, 4 };
    int returnSize; 
    int* result = intersection(nums1, 4, nums2, 3, &returnSize); 
    for (int i = 0; i < returnSize; i++) {
        printf("%d ", result[i]); 
    }
    free(result);
    return 0;
}